package test;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;

public class StoreImage {
    public static void storeImage(String filename) throws Exception {
        Properties prop = new Properties();
        prop.load(new FileInputStream("src/druid.properties"));
        DataSource dataSource= DruidDataSourceFactory.createDataSource(prop);
        Connection connection=dataSource.getConnection();
        String sql = "INSERT INTO image(image) VALUES (?)";
        PreparedStatement pstmt = connection.prepareStatement(sql);
        File file = new File("src/picture/1.png");
        FileInputStream fis = new FileInputStream(file);
        pstmt.setBlob(1, fis);

        pstmt.executeUpdate();
        pstmt.close();
        connection.close();
    }
}
